find_package(PkgConfig)
pkg_check_modules(PC_PLOT plplot)

find_path(PLPLOT_INCLUDE_DIRS
    NAMES plstream.h
    HINTS ${PC_PLPLOT_INCLUDEDIR}
    ${PC_PLPLOT_INCLUDE_DIRS}
)

find_library(PLPLOT_LIBRARIES
    NAMES plplot plplotcxx
    HINTS ${PC_PLOT_LIBDIR}
    ${PC_PLOT_LIBRARY_DIRS}
)

message("PC_PLOT_INCLUDEDIR=${PC_PLOT_INCLUDEDIR} PC_PLOT_LIBDIR=${PC_PLOT_LIBDIR}")
message("PLPLOT_LIBRARIES=${PLPLOT_LIBRARIES} PLPLOT_INCLUDE_DIRS=${PLPLOT_INCLUDE_DIRS} PC_PLOT_VERSION=${PC_PLOT_VERSION}")

if(PLPLOT_INCLUDE_DIRS AND PLPLOT_LIBRARIES)
    set(PLPLOT_FOUND TRUE)
    set(PLPLOT_LIBRARY ${PLPLOT_LIBRARIES})
    set(PLPLOT_INCLUDE_DIR ${PLPLOT_INCLUDE_DIRS})
    set(PLPLOT_VERSION ${PC_PLOT_VERSION})
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PLPLOT REQUIRED_VARS PLPLOT_INCLUDE_DIRS PLPLOT_LIBRARIES
        FOUND_VAR PLPLOT_FOUND VERSION_VAR PLPLOT_VERSION)

mark_as_advanced(PLPLOT_LIBRARIES PLPLOT_LIBRARY PLPLOT_INCLUDE_DIRS PLPLOT_INCLUDE_DIR PLPLOT_FOUND)

